new Vue({
    el: '#app',     
    data() {
      var validateName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入供应商名称'));
        }else{
        	return callback();
        }
      };
      return {
    	table:'',
    	form:'' ,
    	laypage:'' ,
    	layer:'' ,
    	element:'' ,
    	laydate:'' ,
    	upload:'' ,
    	colorpicker:'',//时间组件
    	formEdit:true, 
    	DateForm: {
          name: '',
          remarks: ''
        },
        rules: {
           name: [
		     { required: true,validator: validateName, trigger: 'blur' }
		  ]          
        }
      };
    },
    created(){
//        this.convert();
        this.localStoragefun();
        
    },
    methods: {
      localStoragefun:function(){
    	  var This=this;
    	  layui.use(['table','form','laypage','layer', 'element', 'laydate','upload'], function(){
    		This.thitable = layui.table;
    		This.form=layui.form;
    		This.laypage = layui.laypage ;//分页
    		This.layer = layui.layer ;//弹层
    		This.element = layui.element; //元素操作
    		This.laydate = layui.laydate; //时间组件 
    		This.upload = layui.upload; 
         })
          
      },	
	  convert: function () {
		  axios.post("/sys/getSys.do",{
		        headers: setHeader()
		      }).then((res) => { 
		           this.sys_name='天有其成电力设备运维云平台';
		           this.callname='13651189367';
		           this.banquan='乌海电业局22';
		      }).catch((err) => {		    	 
		    	  this.$message({
                      message: '信息获失败',
                      type: 'warning'
                    });
             });
      },

      submitForm(formName) {
    	var vm = this;
        this.$refs[formName].validate((valid) => {
          if (valid) {//验证成功
        	  var params = new URLSearchParams();
              params.append('userName', this.ruleForm.userName);
              params.append('pwd', this.ruleForm.pwd);
              params.append('ip', this.ruleForm.ip);
              params.append('source', this.ruleForm.source);
        	  axios({
                  method: "post",
                  url: '/supplier/saveSupplier.do',
                  headers: {"token" : "", "isClient":"web",'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                 // withCredentials:true,
                  data:params,
              })
              .then(function(res) {
            	  var Datanum=res.data
            	  if(Datanum.status == 200){
            		  vm.$message({
                          message: Datanum.resultMsg,
                          type: 'success',
                          onClose:function(){
                        	  var index = parent.layer.getFrameIndex(window.name);
    						  window.parent.location.reload();//有提交成功了才刷新那个页面
    					      parent.layui.table.reload("tabledata");
    					      parent.layer.close(index);//关闭弹出的子页面窗口
                          }
                        });
            		  
            	  }else if(Datanum.status == 666){
	  					TIMEOUT();  
	  	          }else{
	        		  vm.$message({
	                      message: Datanum.resultMsg,
	                      type: 'warning'
	                   });                                      
            	  }            	            	  
             })
          } else {
        	  vm.$message({
                  message: '信息错误',
                  type: 'warning'
               });
            return false;
          }
        });
      }
    }  
 })